<#import "../common/layout.ftl" as layout/>
<#import "../common/dataTables.ftl" as dataTables/>
<#import "../common/modern-forms.ftl" as mform/>
<#import "../common/modal.ftl" as modal/>
<!DOCTYPE html>
<html>
<@layout.head title="人事管理">
    <@dataTables.head/>
    <@dataTables.buttons_head/>
    <@dataTables.select_head/>
    <@dataTables.editor_head/>
    <@dataTables.fixedHeader_head/>
    <@mform.head/>
    <@select.head/>
</@layout.head>
<body>
<@layout.page>
<div class="main-box">
    <div class="content">
    <#--顶部-->
        <div id="searchGroup" class="btn-group" style="position: absolute; ">
            <div style='float:left;margin:5px' class="organizationBox">
                <select class='form-control' id='organization0' onchange="changeOrg(this)">
                    <option value="0">全部一级机构</option>
                    <#list organizationName as item>
                        <option value="${item.id?c}">${item.name}</option>
                    </#list>
                </select>
            </div>
            <div style='float:left;margin:5px'>
                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                        style="margin-left: 5px;"
                        onclick="javascript:refreshOrganization();">
                    <i class="fa fa-search"></i> 查询机构
                </button>
                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                        onclick="javascript:refreshStaff();">
                    <i class="fa fa-search"></i> 查询人员
                </button>
            </div>
        </div>
        <!-- 表格 -->
        <div style="position: relative; ">
            <div style="width:100%;display: flex;">
                <div style="width:400px;position: relative">
                    <div style="position: absolute; top:80px;left:0px;width: 100% ">

                        <@dataTables.commonTable id="mainTable1"/>
                    </div>

                    <div id="btnGroup" class="btn-group" style="position: absolute; top:40px;">
                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                onclick="javascript:addMain();">
                            <i class="fa fa-plus"></i> 添加一级机构
                        </button>

                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:addSon();">
                            <i class="fa fa-edit"></i> 添加子机构
                        </button>
                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:editdetailOrganization();">
                            <i class="fa fa-edit"></i> 修改
                        </button>

                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:deldetailOrganization();">
                            <i class="fa fa-minus"></i> 删除
                        </button>

                    </div>

                </div>
                <div style="width: 10px;"></div>
                <div style="flex: 1;position: relative">
                    <div style="position: absolute; top:45px;left:0px;">
                        <@dataTables.commonTable id="mainTable2"/>
                    </div>
                    <div id="searchGroup" class="btn-group" style="position: absolute; ">
                        <input id="staffInformation" name="staffInformation" placeholder='姓名/手机号'
                               style="margin-left:135px; display: none"/>

                    </div>
                    <div id="btnGroup" class="btn-group" style="position: absolute; top:40px;">

                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:newdetailStaff();">
                            <i class="fa fa-plus"></i> 添加人员
                        </button>

                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:editdetailStaff();">
                            <i class="fa fa-edit"></i> 修改人员
                        </button>

                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:deldetailStaff();">
                            <i class="fa fa-minus"></i> 删除人员
                        </button>
                        <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm"
                                style="margin-left: 5px;"
                                onclick="javascript:yzm();">
                            <i class="fa fa-refresh"></i> 重置验证码
                        </button>
                        <div style='float:left;margin:5px'>
                            <select class='form-control' id='wxSearch' onchange="refreshStaff()">
                                <option value="0">全部</option>
                                <option value="1">已认证微信</option>
                                <option value="2">未认证微信</option>
                            </select>
                        </div>
                    </div>

                </div>
            </div>

        </div>

    </div>
</div>
    <@modal.editModal id="modal-detail" buttonId="btndetailSave" width="450px" height="100px">
        <@mform.container  id="editForm">
        <input id="id" name="id" type="hidden"/>
        <input id="superOrganizationId" name="superOrganizationId" type="hidden"/>
        <input id="organizationType" name="organizationType" value="400001" type="hidden"/>
            <@mform.row>
                <@mform.input_text id='name' name='name' size=6 label='机构名称' placeholder='机构名称' icon='fa-edit' />
                <@mform.input_text id='code' name='code' size=6 label='机构编号' placeholder='机构编号' icon='fa-edit' />
            </@mform.row>
            <@mform.row>
                <@mform.select2 id='warehouseFlag' name='warehouseFlag' label="是否允许创建仓库"  size=6>
                    <#list warehouseFlag as item>
                    <option value="${item.code}">${item.name}</option>
                    </#list>
                </@mform.select2>
            </@mform.row>
        </@mform.container>
    </@modal.editModal>
    <@modal.editModal id="modal-detail1" buttonId="btndetailSave1" width="600px" height="100px" >
        <@mform.container  id="editForm1">
        <input id="id" name="id" type="hidden"/>
        <input id="wxId" name="wxId" type="hidden"/>
        <input id="organizationId" name="organizationId" type="hidden"/>
            <@mform.row>
                <@mform.input_text id='name' name='name' size=6 label='人员姓名' placeholder='人员姓名' icon='fa-edit' />
                <@mform.input_text id='telephone' name='telephone' size=6 label='认证号（不可重复）' placeholder='手机号或其他唯一标识信息' icon='fa-edit' />
            </@mform.row>
            <@mform.row>
                <@mform.input_text id='job' name='job' size=6 label='职务' placeholder='职务' icon='fa-edit' />
                <@mform.select2 id='role' name='role' label="角色"  size=6>
                <option value="5" selected="selected">默认普通用户</option>
                    <#list staffRole as item>
                    <option value="${item.cRoleID}">${item.cRoleName}</option>
                    </#list>
                </@mform.select2>
            <#--
             <@mform.input_text id='role' name='role' size=6 label='角色' placeholder='角色' icon='fa-edit' />-->
            </@mform.row>
            <@mform.row>
                <@mform.input_text id='telephone2' name='telephone2' size=6 label='审务终端号' placeholder='审务终端号' icon='fa-edit' />
                <@mform.input_text id='telephone3' name='telephone3' size=6 label='完整手机号' placeholder='完整手机号' icon='fa-edit' />
            </@mform.row>
            <@mform.row>
                <@mform.input_text id='roomNo' name='roomNo' size=6 label='房间号' placeholder='房间号' icon='fa-edit' />
                <@mform.input_text id='telephone4' name='telephone4' size=6 label='固定电话' placeholder='固定电话' icon='fa-edit' />
            </@mform.row>
            <@mform.row>
                <@mform.date id='birthday' name='birthday' size=6 title='出生日期'  />
                <@mform.select2 id='staffType' name='staffType' label="人员类型"  size=6>
                    <#list staffType as item>
                    <option value="${item.code}" pym="${item.pym}">${item.name}</option>
                    </#list>
                </@mform.select2>
            </@mform.row>
            <@mform.row>
                <@mform.select2 id='wxState' name='wxState' label="微信状态"  size=6>
                <option value="" selected="selected">未绑定</option>
                <option value="199001">启用</option>
                <option value="199002">停用</option>
                </@mform.select2>
                <@mform.input_text id='tips' name='tips' size=6 label='备注（100字内）' placeholder='备注（100字内）' icon='fa-edit' />
            </@mform.row>
            <@mform.row>
            <#-- <@mform.input_text id='organizationId' name='organizationId' size=6 label='所属机构id' placeholder='所属机构id' icon='fa-edit' />-->

            </@mform.row>
        </@mform.container>
    </@modal.editModal>
</@layout.page>
<@layout.foot>
    <@dataTables.foot/>
    <@dataTables.buttons_foot/>
    <@dataTables.select_foot/>
    <@dataTables.fixedHeader_foot/>
    <@dataTables.editor_foot/>
    <@mform.foot/>
<script src="${request.contextPath}/assets/js/jquery.serializejson.min.js?v=3653060703"></script>
<script type="text/javascript">
    var staffType = {
        <#list staffType as item>
            "${item.code}": "${item.name}",
        </#list>}
    var warehouseFlag = {
        <#list warehouseFlag as item>
            "${item.code}": "${item.name}",
        </#list>}
    var columns1 = [
        {'sWidth': '100px', 'title': 'id', 'data': 'id'},
        {'sWidth': '100px', 'title': '机构名称', 'data': 'name'},
        {'sWidth': '100px', 'title': '机构编码', 'data': 'code'},
        {'sWidth': '50px', 'title': '仓库', 'data': 'warehouseFlag'}
    ]
    var mainTable1 = $('#mainTable1').winningTable({
        columns: columns1,
        pageLength: 10,
        fixedHeader: false,
        searching: false,
        ordering: false, dom: 'Bfrtip',
        "columnDefs": [{
            "targets": [0],
            "visible": false
        }], "rowCallback": function (row, data, index) {
            $('td', row).eq(2).html(warehouseFlag[data.warehouseFlag]);
        },
        buttons: []
    });
    $("#mainTable1").css("cssText", "margin-top:0px !important");

    var columns2 = [
        {'sWidth': '100px', 'title': 'ID', 'data': 'id'},
        {'sWidth': '150px', 'title': 'pym', 'data': 'pym'},
        {'sWidth': '150px', 'title': '所属机构', 'data': 'orgName'},
        {'sWidth': '150px', 'title': '人员姓名', 'data': 'name'},
        {'sWidth': '150px', 'title': '认证号', 'data': 'telephone'},
        {'sWidth': '150px', 'title': '职务', 'data': 'job'},
        {'sWidth': '150px', 'title': '出生日期', 'data': 'birthday'},
        {'sWidth': '150px', 'title': '审务终端号', 'data': 'telephone2'},
        {'sWidth': '150px', 'title': '完整手机', 'data': 'telephone3'},
        {'sWidth': '100px', 'title': '房间号', 'data': 'roomNo'},
        {'sWidth': '100px', 'title': '固定电话', 'data': 'telephone4'},
        {'sWidth': '100px', 'title': '类型', 'data': 'staffType'},
        {'sWidth': '120px', 'title': '角色', 'data': 'cRoleName'},
        {'sWidth': '50px', 'title': '验证码', 'data': 'validCode'},
        {'sWidth': '200px', 'title': '微信昵称', 'data': 'wxName'},
        {'sWidth': '150px', 'title': '认证时间', 'data': 'validTime'},
        {'sWidth': '150px', 'title': '创建时间', 'data': 'createTime'}
    ]
    var mainTable2 = $('#mainTable2').winningTable({
        columns: columns2,
        pageLength: 10,
        fixedHeader: false,
        searching: true,
        ordering: false, dom: 'Bfrtip',
        "columnDefs": [{
            "targets": [0, 1],
            "visible": false
        }],
        buttons: [],
        "rowCallback": function (row, data, index) {
            $('td', row).eq(9).html(staffType[data.staffType]);
            if (data.validState == '100002')
                $('td', row).eq(11).html("<span style='color: #cc9c18;'>" + data.validCode + "</span>");
            if (data.wxState == '199002')
                $('td', row).eq(12).html("<span style='color: #cc0d11;'>" + data.wxName + "</span>");
        }
    });

    function getParentOrg() {
        var parent = "0";
        var name = "全部一级机构";
        var boxs = $(".organizationBox");
        for (var i = boxs.length - 1; i >= 0; i--) {
            if ($(boxs[i]).find("select").val() != 0) {
                parent = $(boxs[i]).find("select").val();
                name = $(boxs[i]).find("option:selected").text();
                break;
            }
        }
        return {
            id: parent, name: name
        }
    }

    // 机构查询
    function refreshOrganization(orgLevel) {
        var data = {
            datas: JSON.stringify({
                oneOrganization: getParentOrg().id
            })
        }
        mainTable1.queryData("${request.contextPath}/cust/organization/queryList", data, function (serverData) {
            var data = serverData.data;
            var boxs = $(".organizationBox");
            if (boxs.length > 1 && $(boxs[boxs.length - 1]).find("select").val() == 0) {
                $(boxs[boxs.length - 1]).remove();
            }
            if (orgLevel == null) {
                orgLevel = $(".organizationBox").length - 1;
            }
            if (serverData.recordsTotal >= 0 && $("#organization" + orgLevel).val() != 0) {
                //动态加载下拉框
                var div = $("<div style='float:left;margin:5px' class='organizationBox'> </div>");
                var select = $("<select class='form-control' onchange='changeOrg(this)' id='organization" + (orgLevel - 0 + 1) + "')> <option value=0>全部子机构</option> </select>");
                $("#organization" + orgLevel).parent().after(div.append(select));
                for (var i = 0; i < data.length; i++) {
                    select.append("<option value='" + data[i].id + "'>" + data[i].name + "</option>");
                }
                select.select2();
            }
        });
    }

    function changeOrg(e) {
        var select = $(e);
//        if(select.val()==0){
        var box = select.parent();
        while (box.next().hasClass("organizationBox")) {
            box.next().remove();
        }
//        }
    }

    refreshOrganization(0);

    // 人员查询
    function refreshStaff() {
        var oid = null;
        var datas = mainTable1.getSelectedDatas();
        if (datas.length == 1) {
            oid = datas[0].id;
        } else {
            oid = getParentOrg().id;
        }

        var data = {
            datas: JSON.stringify({
                organizationId: oid,
                wxSearch: $("#wxSearch").val(),
                staffInformation: $("#staffInformation").val()
            })
        }
        mainTable2.queryData("${request.contextPath}/cust/staff/queryList", data);
    }

    refreshStaff();

    //新建一级机构
    function addMain() {
        $('#modal-detail').find(".modal-title").text('添加一级机构');
        clearForm($('#modal-detail'));
        $("#btndetailSave").unbind();
        $("#btndetailSave").click(saveMainOrganization);
        $('#modal-detail').modal();
    }

    // 添加子机构
    function addSon() {
        var superOrg = getParentOrg();
        if (superOrg.id == 0 || $('#organization0').val() == 0) {
            swal("错误", "请选择下拉框中的机构", "error");
            return;
        }

        $('#modal-detail').find(".modal-title").text('添加【' + superOrg.name + '】的子机构');
        clearForm($('#modal-detail'));
        $("#btndetailSave").unbind();
        $('#modal-detail').find("#superOrganizationId").val(superOrg.id);
        $("#btndetailSave").click(saveOrganization);
        $('#modal-detail').modal();
    }

    function editdetailOrganization() {
        var datas = mainTable1.getSelectedDatas();
        if (datas == null || datas.length == 0 || datas.length > 1) {
            swal("错误", "请选择一行数据", "error");
            return;
        }
        var $modal = $("#modal-detail");
        $modal.find(".modal-title").text("修改机构信息");
        clearForm($modal);
        var data = datas[0];
        initFormItemData($("#editForm"), data);
        $modal.modal();
        $("#btndetailSave").unbind();
        $("#btndetailSave").click(editOrganization);
//        $('#modal-detail').find("#superOrganizationId").parent().attr("style", "display:none");
    }

    //添加人员
    function newdetailStaff() {
        var datas = mainTable1.getSelectedDatas();
        if (datas.length == 1) {
            oid = datas[0].id;
            name = datas[0].name
        } else {
            oid = getParentOrg().id;
            name = getParentOrg().name;
        }
        if (oid == 0) {
            swal("错误", "请选择机构", "error");
            return;
        }
        $('#modal-detail1').find(".modal-title").text('为' + name + '：新增人员');
        clearForm($('#modal-detail1'));
        $("#btndetailSave1").unbind();
        $("#btndetailSave1").click(saveStaff);
        $('#modal-detail1').find("#organizationId").val(oid);
        $('#modal-detail1').modal();
    }

    //修改人员信息
    function editdetailStaff() {
        var datas = mainTable2.getSelectedDatas();
        if (datas == null || datas.length == 0 || datas.length > 1) {
            swal("错误", "请选择一行数据", "error");
            return;
        }
        var $modal = $("#modal-detail1");
        $modal.find(".modal-title").text("修改人员信息");
        clearForm($modal);
        var data = datas[0];
        initFormItemData($("#editForm1"), data);
        $modal.modal();
        $("#btndetailSave1").unbind();
        $("#btndetailSave1").click(saveStaff);
    }

    //验证码
    function yzm() {
        var datas = mainTable2.getSelectedDatas();
        if (datas == null || datas.length == 0 || datas.length > 1) {
            swal("错误", "请选择一行数据", "error");
            return;
        }
        var data1 = datas[0];
        var data = {
            datas: JSON.stringify({
                id: data1.id
            })
        }
        swal({
            title: "确定重置此验证码",
            text: "是否确定修改此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (result.value)
                mainTable2.queryData("${request.contextPath}/cust/staff/editYZM", data);
            refreshStaff();
        })

    }

    function saveOrganization() {
        swal({
            title: "确定保存",
            text: "是否确定保存此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            var requestData = $("#modal-detail form").serializeJSON();
            var params = {datas: JSON.stringify(requestData)};
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/organization/save',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            $("#modal-detail").modal('hide');
                            refreshOrganization();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }

    function saveMainOrganization() {
        swal({
            title: "确定保存",
            text: "是否确定保存此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            var requestData = $("#modal-detail form").serializeJSON();
            requestData.organizationType = "400001";
            var params = {datas: JSON.stringify(requestData)};
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/organization/save',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            $("#modal-detail").modal('hide');
                            refreshOrganization();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }

    function editOrganization() {
        swal({
            title: "确定保存",
            text: "是否确定保存此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            var requestData = $("#modal-detail form").serializeJSON();
            var params = {datas: JSON.stringify(requestData)};
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/organization/save',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            $("#modal-detail").modal('hide');
                            refreshOrganization();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }

    function saveStaff() {
        swal({
            title: "确定保存",
            text: "是否确定保存此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            var requestData = $("#modal-detail1 form").serializeJSON();
            if (requestData.wxId == "" && requestData.wxState != "") {
                swal("错误", "此人未绑定微信，请勿修改微信状态", "error");
                return;
            }
            var params = {datas: JSON.stringify(requestData)};
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/staff/save',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            $("#modal-detail1").modal('hide');
                            refreshStaff();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }

    function password() {
        var datas = mainTable2.getSelectedDatas();
        if (datas == null || datas.length == 0 || datas.length > 1) {
            swal("错误", "请选择一行数据", "error");
            return;
        }
        var data = datas[0];
        var params = {
            datas: JSON.stringify({
                id: data.id.toString()
            })
        };
        swal({
            title: "确定初始化密码",
            text: "是否确定初始化密码为123456",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/staff/password',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            $("#modal-detail1").modal('hide');
                            refreshStaff();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }

    // 删除机构
    function deldetailOrganization() {
        var datas = mainTable1.getSelectedDatas();
        if (datas == null || datas.length == 0 || datas.length > 1) {
            swal("错误", "请选择一行数据", "error");
            return;
        }
        var data = datas[0];
        swal({
            title: "确定删除",
            text: "是否确定删除此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            var requestData = {
                id: data.id
            };
            var params = {datas: JSON.stringify(requestData)};
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/organization/delete',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            refreshOrganization();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }

    // 删除人员
    function deldetailStaff() {
        var datas = mainTable2.getSelectedDatas();
        if (datas == null || datas.length == 0 || datas.length > 1) {
            swal("错误", "请选择一行数据", "error");
            return;
        }
        var data = datas[0];
        swal({
            title: "确定删除",
            text: "是否确定删除此数据",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的,确定",
            cancelButtonText: "取消"
        }).then(function (result) {
            if (!result.value)
                return;
            var requestData = {
                id: data.id,
                code:data.telephone
            };
            var params = {datas: JSON.stringify(requestData)};
            $.ajax({
                type: 'POST',
                data: params,
                url: '${request.contextPath}/cust/staff/delete',
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        swal({
                            title: "成功",
                            text: "操作成功!",
                            type: "success",
                            showCancelButton: false,
                            confirmButtonText: "确定"
                        }).then(function (result) {
                            refreshStaff();
                        });
                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        });
    }
</script>
</@layout.foot>
</body>
</html>